<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    
    ul {
      list-style: none;
    }
    
    .box {
      width: 730px;
      height: 454px;
      padding: 8px;
      border: 1px solid green;
      margin: 100px auto;
    }
    
    .inner {
      position: relative;
      overflow: hidden;
      height: 454px;
    }
    
    #imglist {
      width: 700%;
      position: absolute;
      left: 0;
    }
    
    li {
      float: left;
    }
    
    .list {
      position: absolute;
      bottom: 20px;
      left: 50%;
      margin-left: -85px;
    }
    
    .list i {
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: #fff;
      color: #333;
      float: left;
      font-style: normal;
      line-height: 20px;
      font-size: 14px;
      text-align: center;
      margin-right: 10px;
      cursor: pointer;
    }
    
    .list i:last-child {
      margin-right: 0;
    }
    
    .list i.current {
      background-color: skyblue;
      color: #fff;
    }
    
    .arrow {
      position: absolute;
      width: 100%;
      top: 50%;
      margin-top: -30px;
    }
    
    .arrow-left, .arrow-right {
      width: 30px;
      height: 60px;
      position: absolute;
      font: 20px/60px "consolas";
      color: #fff;
      background-color: rgba(0, 0, 0, .3);
      text-align: center;
      cursor: pointer;
    }
    
    .arrow-right {
      right: 0;
    }
  </style>

</head>
<body>

<div class="box" id="box">
  <div class="inner" id="inner">
    <ul id="imglist">
      <li><a href="#"><img src="img/1.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/2.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/3.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/4.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/5.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/6.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/1.jpg" alt=""></a></li>
    </ul>
    <div class="list">
      <i class="current">1</i>
      <i>2</i>
      <i>3</i>
      <i>4</i>
      <i>5</i>
      <i>6</i>
    </div>
    <div class="arrow">
      <span class="arrow-left">&lt;</span>
      <span class="arrow-right">&gt;</span>
    </div>
  </div>
</div>

</body>
</html>
<script src="animate.js"></script>
<script src="./jq/jquery-1.12.2.js"></script>
<script>

  /**
   *
   * 思路：
   * 鼠标移入自动轮播停止；鼠标移出鼠标自动轮播
   * 左边按钮：当点击左边按钮的时候，让图片向右移动，实际上移动的是大ul
   * 右边按钮：当点击右边按钮的时候，让图片向左移动，实际上移动的是大ul
   *
   */

    var imgWidth = document.querySelector('img').width;
    var ul = document.querySelector('ul');
    // var list = document.querySelector('.list');
    // console.log(imgWidth);
  $(function(){
    
    //下方小圆点完成
    var index = 0;
    $(".list i").on("mouseover", function(){
      index = $(this).index();
      $(this).addClass("current").siblings().removeClass("current");

      var target = $(this).index() * imgWidth * (-1);
    animate(ul, target, 40);
    for (var j = 0; j < $(".list").length; j++) {
      $(this)[j].removeAttribute("class");
    }
    $(this).addClass("current");
    // var currentIndex = this.index();
    });

    //点击左边按钮
    $(".arrow-left").on("click",function(){
      if(index == 0){
        index = 5;
        ul.style.left = (ul.children.length - 1) * imgWidth * (-1) + "px";
      } else {
        index--;
      }
      $(".list i").eq(index).addClass("current").siblings().removeClass("current");

      var target = index * imgWidth * (-1);
      animate(ul, target, 40);
    for (var j = 0; j < $(".list").length; j++) {
      $(this)[j].removeAttribute("current");
    }
    $(this).addClass("current");

    });

    //点击右边按钮
    $(".arrow-right").on("click",function(){
      moveRight();
    });

    //封装向右移动的函数
    function moveRight(){
      if (index == 6) {
        index = 0;
        ul.style.left = 0;
      }
      index++;
      var target = index * imgWidth * (-1);
      animate(ul, target, 40);

      for (var j = 0; j < $(".list").length; j++) {
        $(".list i")[j].removeAttribute("class");
      }
      if (index == 6) {
        $(".list i").eq(0).addClass("current").siblings().removeClass("current");
      } else {
        $(".list i").eq(index).addClass("current").siblings().removeClass("current");
      }
    }

    var timer = setInterval(moveRight, 2000);
    $("#box").on("mouseover",function () {
      clearInterval(timer);
    });
    $("#box").on("mouseout",function () {
      timer = setInterval(moveRight, 2000);
    });
  });




</script>